package com.hx.reflect;

import com.hx.reflect.bean.Student;

/**
 * 获取class实例,方式三用的比较多
 *
 * @author jxlgcmh
 * @create 2019-05-11 10:36
 */
public class Demo2 {
    public static void main(String[] args) throws ClassNotFoundException {
        //方式一：通过运行时类的属性
        Class<Student> s1 = Student.class;

        //方式二：通过运行时类的对象
        Student student = new Student();
        Class<? extends Student> s2 = student.getClass();

        //方式三：通过Class的静态方法forName
        Class<?> s3 = Class.forName("com.hx.bean.Student");

        //方式四：通过类加载器
        ClassLoader loader = Demo2.class.getClassLoader();
        Class<?> s4 = loader.loadClass("com.hx.bean.Student");
        System.out.println(s1 == s2 && s2 == s3 && s3 == s4);

    }
}
